package org.xhnews;

import net.rim.device.api.system.ApplicationManager;

import org.xhnews.bo.WeatherBo;
import org.xhnews.constant.Constant;
import org.xhnews.database.DatabaseManager;
import org.xhnews.log.RaspberryLogger;
import org.xhnews.preferences.Preferences;
import org.xhnews.utils.FileUtil;

public class InitBo {
	private Thread _thread;

	public InitBo() {
		_thread = new Thread(new InitJob());

	}

	public void start() {
		_thread.start();
	}

	public class InitJob extends Thread {
		public void run() {
			ApplicationManager am = ApplicationManager.getApplicationManager();
			while (am.inStartup()) {
				try {
					sleep(2000);
				} catch (Exception e) {
					RaspberryLogger.getInstance().error(e);
				}
			}
			FileUtil.makePicDir(Constant.PATH_ROOT);
			FileUtil.makePicDir(Constant.PATH_DATA);
			FileUtil.makePicDir(Constant.PATH_DB);
			DatabaseManager.initDataBase();
			WeatherBo wb = new WeatherBo();
			wb.initCitiesAndProvincesDB();
			Preferences.running_count++;
			Preferences.save();
		}
	}
}
